import { util } from "./@nasty/Util";

/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { currentUser?: any } | undefined, v: any) {
  const currentUser = initialState?.currentUser ?? {};
  return {
    verify: (route: any) => {
      let roles: string[] = route.roles || [];
      let permissions: string[] = route.permissions || [];
      if (roles.length == 0 && permissions.length == 0) return true;
      let isUnion = route.isUnion || false;
      return util.verify(roles, permissions, isUnion);
    },
  };
}
